package com.yyx.up.web.controller;

import com.yyx.up.web.bean.WatchLog;
import com.yyx.up.web.service.WatchLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description: 观影日志的控制器对象
 * @Author: yyx
 * @Create: 2023/5/8 23:26
 * @Version: 8
 */
@Controller
public class WatchLogController {
    @Autowired
    private WatchLogService watchLogService;

    // 各年龄段观影偏好
    @RequestMapping("/queryAgeDatas")
    public String queryAgeDatas(String ageRange, String year, Model model){
        List<WatchLog> logs = watchLogService.queryAgeDatas(ageRange,year);
        Map<String,String> paramMap = new HashMap<String,String>();
        paramMap.put("0","0-9");
        paramMap.put("1","10-19");
        paramMap.put("2","20-29");
        paramMap.put("3","30-39");
        paramMap.put("4","40-49");
        paramMap.put("5","50-59");
        paramMap.put("6","60-69");
        paramMap.put("7","70-79");
        paramMap.put("8","80-89");
        paramMap.put("9","90-99");
        model.addAttribute("watchlogs",logs);
        model.addAttribute("ageRange",paramMap.get(ageRange));
        model.addAttribute("year",year);
        return "queryAgeDatas";
    }

    // 电影收视数据
    @RequestMapping("/queryFilmDatas")
    public String queryFilmDatas(String film_type, String year, Model model){
        List<WatchLog> logs = watchLogService.queryFilmDatas(film_type,year);
        model.addAttribute("watchlogs",logs);
        model.addAttribute("film_type",film_type);
        model.addAttribute("year",year);
        return "queryFilmDatas";
    }

    // 不同性别观影偏好
    @RequestMapping("/queryGenderDatas")
    public String queryGenderDatas(String gender, String year,Model model){
        List<WatchLog> logs = watchLogService.queryGenderDatas(gender,year);
        model.addAttribute("watchlogs",logs);
        model.addAttribute("gender",gender);
        model.addAttribute("year",year);
        return "queryGenderDatas";
    }

    // 数据大屏跳转
    @RequestMapping("/toDataScreen")
    public String toDataScreen(){
        return "toDataScreen";
    }

    // 数据大屏
    @RequestMapping("/DataScreen")
    public String DataScreen(String tel,String year,Model model){
        List<WatchLog> agelogs = watchLogService.queryusersAgeDatas(tel,year);
        model.addAttribute("agelogs",agelogs);
        List<WatchLog> yearlogs = watchLogService.queryYearDatas(tel,year);
        model.addAttribute("yearlogs",yearlogs);
        List<WatchLog> preferencelogs = watchLogService.queryPreferenceDatas(tel,year);
        model.addAttribute("preferencelogs",preferencelogs);
        List<WatchLog> filmsumlogs = watchLogService.filmSum(tel,year);
        model.addAttribute("filmsumlogs",filmsumlogs);
        List<WatchLog> usersumlogs = watchLogService.userSum(tel,year);
        model.addAttribute("usersumlogs",usersumlogs);
        model.addAttribute("tel",tel);
        model.addAttribute("year",year);
        return "DataScreen";
    }
}
